package com.atguigu.bean.com.atguigu.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author wk
 * @create 2021-05-30 16:21
 */
public class SqlSessionUtils {
    /**
     * @author wk
     * @create 2021-05-27 15:32
     * 获取sqlSession的工具类
     */
    @SuppressWarnings("all")
        public static SqlSession getSqlsession() {
            SqlSession sqlSession = null;
            try {
                InputStream is = Resources.getResourceAsStream("mybatis-config.xml");
                sqlSession = new SqlSessionFactoryBuilder().build(is).openSession(true);

            } catch (IOException e) {
                e.printStackTrace();
            }
            return sqlSession;

        }
    }

